package at.fhj.itm11.forum.service.converter;

import java.util.ArrayList;
import java.util.List;

import at.fhj.itm11.forum.model.User;
import at.fhj.itm11.forum.service.dtos.UserDTO;

public class UserDTOConverter implements DTOConverter<UserDTO, User> {

	@Override
	public UserDTO convertToDto(User entity) {
		if(entity != null) {
			UserDTO userDto = new UserDTO();
			userDto.setId(entity.getId());
			userDto.setUsername(entity.getUsername());
			userDto.setAvatarFilePath(entity.getAvatarFilePath());
			
			return userDto;
		}
		
		return null;
	}

	@Override
	public List<UserDTO> convertToDto(List<User> entities) {
		List<UserDTO> userDtoList = new ArrayList<UserDTO>();
		
		for(User userEntity : entities) {
			userDtoList.add(convertToDto(userEntity));
		}
		
		return userDtoList;
	}

	@Override
	public User convertToEntity(UserDTO dto) {
		User u = new User();
		u.setId(dto.getId());
		u.setUsername(dto.getUsername());
		u.setAvatarFilePath(dto.getAvatarFilePath());
		
		return u;
	}

}
